<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="MasterPages/MasterPage.master" Title="Contact Person Manager" Culture="auto" meta:resourcekey="PageResource1" %>
<%@ Register Src="Controls/ErrorList.ascx" TagName="ErrorList" TagPrefix="isp" %>
<asp:Content ContentPlaceHolderID="cphMain" ID="cpMain" runat="server">
	<div>
		<asp:UpdatePanel ID="UpdatePanel1" runat="server">
			<ContentTemplate>
				<asp:Button ID="btnNew" runat="server" OnClick="btnNew_Click" Text="Create new Contact Person" meta:resourcekey="btnNewResource1" /><br />
				<br />
				<asp:GridView ID="gvContactPersons" runat="server" AutoGenerateColumns="False" DataSourceID="odsContactPersons" DataKeyNames="Id" OnRowCommand="gvContactPersons_RowCommand" AllowPaging="True" CellPadding="4" GridLines="None" AllowSorting="True" OnRowCreated="gvContactPersons_RowCreated" meta:resourcekey="gvContactPersonsResource1">
					<Columns>
						<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" meta:resourcekey="BoundFieldResource1" />
						<asp:BoundField DataField="FullName" HeaderText="Full Name" ReadOnly="True" SortExpression="FullName" meta:resourcekey="BoundFieldResource2" />
						<asp:BoundField DataField="DateOfBirth" HeaderText="Date of Birth" SortExpression="DateOfBirth" DataFormatString="{0:d}" HtmlEncode="False" meta:resourcekey="BoundFieldResource3" />
						<asp:TemplateField HeaderText="Type" SortExpression="Type">
							<ItemTemplate>
								<asp:Label ID="Label1" runat="server" Text='<%# Helpers.GetTranslation(Eval("Type")) %>'></asp:Label>
							</ItemTemplate>
						</asp:TemplateField>
						<asp:ButtonField CommandName="Addresses" Text="Addresses" meta:resourcekey="ButtonFieldResource1" />
						<asp:ButtonField CommandName="EmailAddresses" Text="Email" meta:resourcekey="ButtonFieldResource2" />
						<asp:ButtonField CommandName="PhoneNumbers" Text="Phonenumbers" meta:resourcekey="ButtonFieldResource3" />
						<asp:TemplateField ShowHeader="False" meta:resourcekey="TemplateFieldResource1">
							<ItemTemplate>
								<asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Edit" CommandArgument='<%# Eval("Id") %>' Text="Edit" meta:resourcekey="lnkEditResource1"></asp:LinkButton>
							</ItemTemplate>
						</asp:TemplateField>
						<asp:TemplateField ShowHeader="False" meta:resourcekey="TemplateFieldResource2">
							<ItemTemplate>
								<asp:LinkButton ID="lnkDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this contact person?');" meta:resourcekey="lnkDeleteResource1"></asp:LinkButton>
							</ItemTemplate>
						</asp:TemplateField>
					</Columns>
				</asp:GridView>
				<br />
				<br />
				<asp:ObjectDataSource ID="odsContactPersons" runat="server" DataObjectTypeName="Spaanjaars.ContactManager.BusinessEntities.ContactPerson" DeleteMethod="Delete" InsertMethod="Save" SelectMethod="GetList" TypeName="Spaanjaars.ContactManager.Bll.ContactPersonManager" UpdateMethod="Save" SortParameterName="sortExpression" EnablePaging="True" SelectCountMethod="SelectCountForGetList"></asp:ObjectDataSource>
				<br />
				<br />
				<asp:MultiView ID="MultiView1" runat="server">
					<asp:View ID="View1" runat="server">
						<fieldset>
							<legend>
								<asp:Localize ID="locAddresses" runat="server" meta:resourcekey="locAddressesResource1" Text="Addresses"></asp:Localize></legend>
							<asp:Button ID="btnNewAddress" runat="server" Text="Create new Address" OnClick="btnNewAddress_Click" meta:resourcekey="btnNewAddressResource1" />
							<asp:GridView ID="gvAddresses" runat="server" AutoGenerateColumns="False" DataKeyNames="Id,ConcurrencyId" DataSourceID="odsAddresses" AllowPaging="True" OnRowUpdating="gvAddresses_RowUpdating" OnRowUpdated="gvAddresses_RowUpdated" meta:resourcekey="gvAddressesResource1">
								<Columns>
									<asp:BoundField DataField="ContactPersonId" ReadOnly="True" HeaderText="Contact Person Id" meta:resourcekey="BoundFieldResource5" />
									<asp:BoundField DataField="Street" HeaderText="Street" SortExpression="Street" meta:resourcekey="BoundFieldResource6" />
									<asp:BoundField DataField="HouseNumber" HeaderText="House Number" meta:resourcekey="BoundFieldResource7" />
									<asp:BoundField DataField="ZipCode" HeaderText="ZipCode" SortExpression="ZipCode" meta:resourcekey="BoundFieldResource8" />
									<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" meta:resourcekey="BoundFieldResource9" />
									<asp:BoundField DataField="Country" HeaderText="Country" meta:resourcekey="BoundFieldResource10" />
									<asp:TemplateField HeaderText="Type" SortExpression="Type" meta:resourcekey="TemplateFieldResource3">
										<EditItemTemplate>
											<asp:DropDownList ID="lstType" runat="server" DataSource="<%# Helpers.GetContactTypes() %>" SelectedValue='<%# Bind("Type") %>' meta:resourcekey="lstTypeResource1" DataValueField="Value" DataTextField="Text" />
										</EditItemTemplate>
										<ItemTemplate>
											<asp:Label ID="Label1" runat="server" Text='<%# Helpers.GetTranslation(Eval("Type")) %>'></asp:Label>
										</ItemTemplate>
									</asp:TemplateField>
									<asp:CommandField ShowEditButton="True" meta:resourcekey="CommandFieldResource1" />
									<asp:TemplateField ShowHeader="False" meta:resourcekey="TemplateFieldResource4">
										<ItemTemplate>
											<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this contact record?');" meta:resourcekey="LinkButton1Resource1"></asp:LinkButton>
										</ItemTemplate>
									</asp:TemplateField>
								</Columns>
							</asp:GridView>
							<asp:FormView ID="fvAddress" runat="server" DataKeyNames="Id" DataSourceID="odsAddresses" DefaultMode="Insert" OnItemInserting="fv_ItemInserting" Visible="False" OnItemCommand="fvAddress_ItemCommand" OnItemInserted="fvAddress_ItemInserted" EnableViewState="False" OnItemUpdating="fvAddress_ItemUpdating" meta:resourcekey="fvAddressResource1">
								<InsertItemTemplate>
									<span class="Label">Street:</span>
									<asp:TextBox ID="StreetTextBox" runat="server" Text='<%# Bind("Street") %>' meta:resourcekey="StreetTextBoxResource1" />
									<br />
									<span class="Label">HouseNumber:</span>
									<asp:TextBox ID="HouseNumberTextBox" runat="server" Text='<%# Bind("HouseNumber") %>' meta:resourcekey="HouseNumberTextBoxResource1" />
									<br />
									<span class="Label">ZipCode:</span>
									<asp:TextBox ID="ZipCodeTextBox" runat="server" Text='<%# Bind("ZipCode") %>' meta:resourcekey="ZipCodeTextBoxResource1" />
									<br />
									<span class="Label">City:</span>
									<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' meta:resourcekey="CityTextBoxResource1" />
									<br />
									<span class="Label">Country:</span>
									<asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' meta:resourcekey="CountryTextBoxResource1" />
									<br />
									<span class="Label">Type:</span>
									<asp:DropDownList ID="lstType" runat="server" DataSource="<%# Helpers.GetContactTypes() %>" SelectedValue='<%# Bind("Type") %>' meta:resourcekey="lstTypeResource2" DataValueField="Value" DataTextField="Text" />
									<br />
									<br />
									<asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" meta:resourcekey="InsertButtonResource1"></asp:LinkButton>
									<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" meta:resourcekey="InsertCancelButtonResource1"></asp:LinkButton>
								</InsertItemTemplate>
							</asp:FormView>
							<br />
							<isp:ErrorList ID="ErrorList1" runat="server" />
							<asp:PlaceHolder ID="plcConcurrency" runat="server" Visible="False">
								<div class="ErrorMessage">
									An error occurred while updating this contact person. Another user has modified the record. What would you like to do?<br />
								</div>
								<asp:Button ID="btnOverwrite" runat="server" OnClick="btnOverwrite_Click" Text="Save changes anyway" meta:resourcekey="btnOverwriteResource1" />
								<asp:Button ID="btnReload" runat="server" OnClick="btnReload_Click" Text="Reload data from database (overwrites your changes)" meta:resourcekey="btnReloadResource1" />
							</asp:PlaceHolder>
							<asp:ObjectDataSource ID="odsAddresses" runat="server" DataObjectTypeName="Spaanjaars.ContactManager.BusinessEntities.Address" DeleteMethod="Delete" InsertMethod="Save" SelectMethod="GetList" TypeName="Spaanjaars.ContactManager.Bll.AddressManager" UpdateMethod="Save" OnInserting="odsAddresses_Inserting" OnInserted="odsAddresses_Inserted">
								<SelectParameters>
									<asp:ControlParameter ControlID="gvContactPersons" Name="contactPersonId" PropertyName="SelectedValue" Type="Int32" />
								</SelectParameters>
							</asp:ObjectDataSource>
						</fieldset>
					</asp:View>
					<asp:View ID="View2" runat="server">
						<fieldset>
							<legend>
								<asp:Localize ID="locEmailAddresses" runat="server" meta:resourcekey="locEmailAddressesResource1" Text="E-mail addresses"></asp:Localize></legend>
							<asp:Button ID="btnNewEmailAddress" runat="server" Text="Create new Email Address" OnClick="btnNewEmailAddress_Click" meta:resourcekey="btnNewEmailAddressResource1" />
							<asp:GridView ID="gvEmailAddresses" runat="server" AutoGenerateColumns="False" DataSourceID="odsEmailAddresses" AllowPaging="True" DataKeyNames="Id,ConcurrencyId" meta:resourcekey="gvEmailAddressesResource1">
								<Columns>
									<asp:BoundField DataField="ContactPersonId" HeaderText="Contact Person Id" SortExpression="ContactPersonId" ReadOnly="True" meta:resourcekey="BoundFieldResource11" />
									<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" meta:resourcekey="BoundFieldResource12" />
									<asp:TemplateField HeaderText="Type" SortExpression="Type" meta:resourcekey="TemplateFieldResource5">
										<EditItemTemplate>
											<asp:DropDownList ID="lstType" runat="server" DataSource="<%# Helpers.GetContactTypes() %>" SelectedValue='<%# Bind("Type") %>' meta:resourcekey="lstTypeResource3" DataValueField="Value" DataTextField="Text" />
										</EditItemTemplate>
										<ItemTemplate>
											<asp:Label ID="Label1" runat="server" Text='<%# Helpers.GetTranslation(Eval("Type")) %>'></asp:Label>
										</ItemTemplate>
									</asp:TemplateField>
									<asp:CommandField ShowEditButton="True" meta:resourcekey="CommandFieldResource2" />
									<asp:TemplateField ShowHeader="False" meta:resourcekey="TemplateFieldResource6">
										<ItemTemplate>
											<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this contact record?');" meta:resourcekey="LinkButton1Resource2"></asp:LinkButton>
										</ItemTemplate>
									</asp:TemplateField>
								</Columns>
							</asp:GridView>
							<asp:FormView ID="fvEmailAddress" runat="server" DataKeyNames="Id" DataSourceID="odsEmailAddresses" OnItemInserting="fv_ItemInserting" DefaultMode="Insert" Visible="False" OnItemCommand="fvEmailAddress_ItemCommand" OnItemInserted="fvEmailAddress_ItemInserted" EnableViewState="False" meta:resourcekey="fvEmailAddressResource1">
								<InsertItemTemplate>
									<span class="Label">Email:</span>
									<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' meta:resourcekey="EmailTextBoxResource1" /><br />
									<span class="Label">Type:</span>
									<asp:DropDownList ID="lstType" runat="server" DataSource='<%# Helpers.GetContactTypes() %>' SelectedValue='<%# Bind("Type") %>' meta:resourcekey="lstTypeResource4" DataValueField="Value" DataTextField="Text" />
									<br />
									<br />
									<asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" meta:resourcekey="InsertButtonResource2"></asp:LinkButton>
									<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" meta:resourcekey="InsertCancelButtonResource2"></asp:LinkButton>
								</InsertItemTemplate>
							</asp:FormView>
						</fieldset>
						<asp:ObjectDataSource ID="odsEmailAddresses" runat="server" DataObjectTypeName="Spaanjaars.ContactManager.BusinessEntities.EmailAddress" DeleteMethod="Delete" InsertMethod="Save" SelectMethod="GetList" TypeName="Spaanjaars.ContactManager.Bll.EmailAddressManager" UpdateMethod="Save" EnablePaging="True" SelectCountMethod="SelectCountForGetList">
							<SelectParameters>
								<asp:ControlParameter ControlID="gvContactPersons" Name="contactPersonId" PropertyName="SelectedValue" Type="Int32" />
							</SelectParameters>
						</asp:ObjectDataSource>
					</asp:View>
					<asp:View ID="View3" runat="server">
						<fieldset>
							<legend>
								<asp:Localize ID="locPhoneNumbers" runat="server" meta:resourcekey="locPhoneNumbersResource1" Text="Phone numbers"></asp:Localize></legend>
							<asp:Button ID="btnNewPhoneNumber" runat="server" Text="Create new Phone Number" OnClick="btnNewPhoneNumber_Click" meta:resourcekey="btnNewPhoneNumberResource1" />
							<asp:GridView ID="gvPhoneNumbers" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="odsPhoneNumbers" DataKeyNames="Id" meta:resourcekey="gvPhoneNumbersResource1">
								<Columns>
									<asp:BoundField DataField="ContactPersonId" HeaderText="Contact Person Id" SortExpression="ContactPersonId" ReadOnly="True" meta:resourcekey="BoundFieldResource13" />
									<asp:BoundField DataField="Number" HeaderText="Number" SortExpression="Number" meta:resourcekey="BoundFieldResource14" />
									<asp:TemplateField HeaderText="Type" SortExpression="Type" meta:resourcekey="TemplateFieldResource7">
										<EditItemTemplate>
											<asp:DropDownList ID="lstType" runat="server" DataSource='<%# Helpers.GetContactTypes() %>' SelectedValue='<%# Bind("Type") %>' meta:resourcekey="lstTypeResource5" DataValueField="Value" DataTextField="Text" />
										</EditItemTemplate>
										<ItemTemplate>
											<asp:Label ID="Label1" runat="server" Text='<%# Helpers.GetTranslation(Eval("Type")) %>'></asp:Label>
										</ItemTemplate>
									</asp:TemplateField>
									<asp:CommandField ShowEditButton="True" meta:resourcekey="CommandFieldResource3" />
									<asp:TemplateField ShowHeader="False" meta:resourcekey="TemplateFieldResource8">
										<ItemTemplate>
											<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this contact record?');" meta:resourcekey="LinkButton1Resource3"></asp:LinkButton>
										</ItemTemplate>
									</asp:TemplateField>
								</Columns>
							</asp:GridView>
							<asp:ObjectDataSource ID="odsPhoneNumbers" runat="server" DataObjectTypeName="Spaanjaars.ContactManager.BusinessEntities.PhoneNumber" DeleteMethod="Delete" InsertMethod="Save" SelectMethod="GetList" TypeName="Spaanjaars.ContactManager.Bll.PhoneNumberManager" UpdateMethod="Save">
								<SelectParameters>
									<asp:ControlParameter ControlID="gvContactPersons" Name="contactPersonId" PropertyName="SelectedValue" Type="Int32" />
								</SelectParameters>
							</asp:ObjectDataSource>
							<asp:FormView ID="fvPhoneNumber" runat="server" DataKeyNames="Id" DataSourceID="odsPhoneNumbers" DefaultMode="Insert" OnItemInserting="fv_ItemInserting" Visible="False" OnItemCommand="fvPhoneNumber_ItemCommand" OnItemInserted="fvPhoneNumber_ItemInserted" EnableViewState="False" meta:resourcekey="fvPhoneNumberResource1">
								<InsertItemTemplate>
									<span class="Label">Number:</span>
									<asp:TextBox ID="NumberTextBox" runat="server" Text='<%# Bind("Number") %>' meta:resourcekey="NumberTextBoxResource2" /><br />
									<span class="Label">Type:</span>
									<asp:DropDownList ID="lstType" runat="server" DataSource='<%# Helpers.GetContactTypes() %>' SelectedValue='<%# Bind("Type") %>' meta:resourcekey="lstTypeResource6" DataValueField="Value" DataTextField="Text" />
									<br />
									<br />
									<asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" meta:resourcekey="InsertButtonResource3"></asp:LinkButton>
									<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" meta:resourcekey="InsertCancelButtonResource3"></asp:LinkButton>
								</InsertItemTemplate>
							</asp:FormView>
							<br />
						</fieldset>
					</asp:View>
				</asp:MultiView>
			</ContentTemplate>
		</asp:UpdatePanel>
	</div>
</asp:Content>
